package rai.service.transport;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class RaiSocket {
	private Socket echange;
	private ObjectOutputStream out;
	private ObjectInputStream in;

	public RaiSocket(Socket echange) throws IOException {
		this.echange = echange;
		out = new ObjectOutputStream(echange.getOutputStream());
		in = new ObjectInputStream(echange.getInputStream());
	}

	public void writeInt(int i) throws IOException {
		out.writeInt(i);
		out.flush();
	}
	
	public void writeString(String s) throws IOException{
		out.writeUTF(s);
		out.flush();
	}
	
	public void writeBoolean(Boolean b) throws IOException{
		out.writeBoolean(b);
		out.flush();
	}

	public void writeObject(Object obj) throws IOException {
		out.writeObject(obj);
		out.flush();
	}
	
	public String readString() throws IOException{
		return in.readUTF();
	}
	
	public Object readObject() throws IOException, ClassNotFoundException{
		return in.readObject();
	}

	public void closeSocket() {
		try {
			echange.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
